package edu.je.column.controller;

import com.junqson.je.common.annotation.LoginRequire;
import com.junqson.je.common.model.ApiResult;
import edu.je.column.model.NewsModel;
import edu.je.column.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author MengXin
 * @description: 新闻控制器模块
 * @program: je-gateway
 * @date 2021/4/21 19:02
 * @mail mx@radish.cloud
 */

@RestController
@RequestMapping("news")
public class NewsController {
    @Autowired
    NewsService newsService;
    /**
     * @param
     * @return com.junqson.je.common.model.ApiResult
     * @author Mengxin
     * @describe: 获取新闻列表
     * @date 2021/4/21 19:06
     */
    @RequestMapping("getAllNews")
    public ApiResult getAllNews(@RequestParam(required = false) Integer page,
                                @RequestParam(required = false) Integer size){
        List<NewsModel> models = newsService.getAllnews(page,size);
        return ApiResult.success(models);
    }
    /**
     * @param title 新闻标题
	 * @param abstractContet 新闻摘要
	 * @param userId 新闻发布者id
	 * @param imageUrl 新闻图片地址
	 * @param content 新闻内容
     * @return com.junqson.je.common.model.ApiResult
     * @author Mengxin
     * @describe: 新增新闻类
     * @date 2021/4/22 15:54
     */
    @RequestMapping("addNews")
    public ApiResult addNews(@RequestParam("title") String title,
                             @RequestParam("abstrcatontent") String abstractContet,
                             @RequestParam("userId") Long userId,
                             @RequestParam("imageUrl") String imageUrl,
                             @RequestParam("content") String content){
        NewsModel model = newsService.addNews(title,abstractContet,userId,imageUrl,content);
        return ApiResult.success(model);
    }
}
